package com.orange.core.service.writeoff;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orange.core.mapper.writeoff.WriteOffMapper;
import com.orange.core.pojo.entity.writeoff.WriteOff;
import com.orange.core.pojo.req.writeoff.WriteOffSaveReq;
import com.orange.core.util.PrincipalUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RequiredArgsConstructor
@Service
public class WriteOffSaveService extends ServiceImpl<WriteOffMapper, WriteOff> {

    /**
     * 核销记录
     */
    @Transactional
    public void writeOff(WriteOffSaveReq req) {
        this.save(new WriteOff()
                .setUserId(req.getUserId())
                .setShopId(req.getShopId())
                .setBusinessId(req.getBusinessId())
                .setBusinessType(req.getBusinessType())
                .setWriteOffDate(LocalDate.now())
                .setWriteOffTime(LocalDateTime.now())
                .setWriteOffBy(PrincipalUtil.getId()));
    }
}
